package com.pphh.demo;

import com.pphh.demo.exception.BlockException;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 11/22/2018
 */
public class BlockingQueueFlowControl extends FlowControl {

    private BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(5);

    @Override
    public void run() throws BlockException {
        if (queue.offer(1)){
            // execute the test task
            test();
            queue.poll();
        } else {
            throw new BlockException("task is blocked by thread pool.");
        }
    }

}
